/**
 * 1.一般函数中使用this,this指代全局对象
 */

 function test1() {
     this.x = 1;
     console.log(this.x);
 }

 test1();//1

 /**
 * 2.作为对象方法调用,this指代上级对象
 */

function test2() {
    console.log(this.x);
}
var obj = {};
obj.x = 1;
obj.m = test2;

obj.m();//1 

// 相当于
var obj = {
    x:1,
    m:function () {
        console.log(this.x);
    }
}
obj.m();

/**
 * 3.作为构造函数调用,this指向new出的对象
 */

 function test3() {
     this.name = "小白";
 }

 var t = new test3();
 console.log(t.name);//"小白"

 /**
  * apply call调用
  */

  function Animal() {
      this.name  = "animal";
  }

  function Cat() {
      Animal.call(this);//将this指向Animal
  }

  var cat  = new Cat();
  console.log(cat.name);//"animal"